﻿Public Class xtf_LISTADOmoneda_

    Public Overrides Sub IniciarLista()
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Identificador (ID)")
            dtt_DataTable.Columns.Add("Nombre")
            dtt_DataTable.Columns.Add("Descripcion")
            dtt_DataTable.Columns.Add("Simbolo")

            gdv_general.PopulateColumns(dtt_DataTable)

            Dim obj_Moneda_ As New cls_Moneda_
            If obj_Moneda_.CargarTodos Then
                For Each Moneda As cls_Moneda_ In obj_Moneda_.Items
                    AgregarItem(Moneda)
                Next
            End If

            'ulg_Lista.DataBind()

            FiltrarColumnas()
            gdc_general.EndUpdate()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Function AgregarItem(ByRef Moneda As cls_moneda_) As DataRow
        Dim Row As DataRow = dtt_DataTable.NewRow
        Row("Identificador (ID)") = Moneda.idMoneda
        Row("Nombre") = Moneda.nombre
        Row("Descripcion") = Moneda.descripcion
        Row("Simbolo") = Moneda.simbolo

        dtt_DataTable.Rows.Add(Row)
        'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
        Return Row
    End Function

    Public Sub ModificarItem(ByRef Moneda As cls_moneda_, ByRef ulg_row As DataRow)
        ulg_row("Identificador (ID)") = Moneda.idMoneda
        ulg_row("Nombre") = Moneda.nombre
        ulg_row("Descripcion") = Moneda.descripcion
        ulg_row("Simbolo") = Moneda.simbolo
    End Sub

    Public Sub New()

        Me.Cursor = Cursors.WaitCursor
        InitializeComponent()
        PERMISONuevo = "001019002"
        PERMISOModificar = "001019003"
        PERMISOEliminar = "001019004"
        PERMISOImprimir = "001019005"
        Me.Text = lbl_modulo.Text : lbl_modulodescripcion.Text = "Listado de " & lbl_modulo.Text & "."
        IniciarLista()
        Me.Cursor = Cursors.Default

    End Sub


    Public Overrides Sub bbi_Eliminar_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        If ComprobarPermiso(PERMISOEliminar) Then
            Try
                If gdv_general.SelectedRowsCount > 0 Then
                    If ErrManagerShow("000005", Me) = DialogResult.Yes Then
                        Dim objeto As Object
                        objeto = Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Replace(Me.Name, "xtf_LISTADO", "cls_"), True, True))
                        If gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Identificador (ID)") <> 1 Then
                            objeto.Eliminar(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Identificador (ID)"))
                            dtt_DataTable.Rows.Remove(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0)))
                        Else
                            ErrManagerShow("Restriccion de sistema.", "No se puede realizar la operacion solicitada." & vbNewLine & "Accion o registro protegido por sistema.", DevEx.xtf_ErrManagerAlerta.errManagerImg.img_Error, DevEx.xtf_ErrManagerAlerta.errManagerBtn.btn_Aceptar)
                        End If
                    End If
                End If
            Catch ex As Exception
                'Dim frmError As New frm_ErrorManager(ex.Message)
            End Try
        End If

    End Sub

End Class